//时间格式为文本，例如："2016/11/2,12:32:34或者2016-11-02 12:34:21";
function textCountDown(time,id,text){
	var date = new Date();
	var endTime = new Date(time);
	var LeftTime = parseInt((endTime.getTime() - date.getTime())/1000);
	var day = parseInt(LeftTime/(60*60*24));
	var hour = parseInt(LeftTime/(60*60)%24);
	var minute = parseInt(LeftTime/60%60);
	var second = parseInt(LeftTime%60);
	document.getElementById(id).innerHTML = day + '天' + hour + '小时' + minute + '分' + second + '秒';
	if(endTime.getTime() >= date.getTime()){
		setInterval(function(){
			textCountDown(time,id,text);
		},1000);
	}else{
		document.getElementById(id).innerHTML = text;
	}
} 

//arr= ['2016/11/02,12:34:42',类型,id,text];1:天、小时、分、秒；2、小时、分、秒；3、分、秒；4、秒；
function countDown(arr){
	var startTime = new Date();
	var endTime = new Date(arr.endTime);
	var array = [];
	var LeftTime = parseInt((endTime.getTime() - startTime.getTime())/1000);
	array[0] = parseInt(LeftTime/(60*60*24));
	array[1] = parseInt(LeftTime/(60*60)%24);
	array[2] = parseInt(LeftTime/60%60);
	array[3] = parseInt(LeftTime%60);
	if (array[3] < 10) {
		array[3] = '0' + array[3];
	};
	if (arr.type == 1) {
		return array;
	}else if (arr.type == 2) {
		array.splice(0,1);
		return array;
	}else if(arr.type ==3) {
		array.splice(0,2);
		return array;
	}else{
		array.splice(0,3);
		return array;
	}
	if(LeftTime > 0){
		setInterval(function(){
			countDown(array);
		},1000);
	}else{
		document.getElementById(id).innerHTML = text;
	}
}


//时间格式为时间戳，例如：1478071392000
function timeStampCountDown(time,id,text){
	var nowTime = new Date();
	var leftTime = parseInt((time - nowTime.getTime())/1000);
	var day = parseInt(leftTime/(60*60*24));
	var hour = parseInt(leftTime/(60*60)%24);
	var minute = parseInt(leftTime/60%60);
	var second = parseInt(leftTime%60);
	document.getElementById(id).innerHTML = day + '天' + hour + '小时' + minute + '分' + second + '秒';
	if(time >= nowTime.getTime()){
		setInterval(function(){
			timeStampCountDown(time,id,text);
		},1000);
	}else{
		document.getElementById(id).innerHTML = text;
	}
}

//时间戳转日期
function getLocalTime(nS) {     
    //return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
    var now=new Date(parseInt(nS));   
    var year=now.getFullYear();
    var month=now.getMonth()+1;
    if(month<10){
        month = "0"+month;
    }
    var date=now.getDate();
    if(date<10){
        date = "0"+date;
    }
    var hour=now.getHours();
    if(hour<10){
        hour = "0"+hour;
    }
    var minute=now.getMinutes();
    if(minute<10){
        minute = "0"+minute;
    }
    var second=now.getSeconds();
    if(second<10){
        second = "0"+second;
    }
    return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;   
}